/**
 * Copyright &copy; 2015-2020 <a href="www.dsesa.cn/">ESA</a> All rights reserved.
 */
package com.jeeplus.modules.sys.service;

import com.jeeplus.core.service.CrudService;
import com.jeeplus.modules.sys.entity.ArchCostItem;
import com.jeeplus.modules.sys.entity.ObjectCostItem;
import com.jeeplus.modules.sys.mapper.ObjectCostItemMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 数据字典Service
 * @author lgf
 * @version 2017-01-16
 */
@Service
@Transactional(readOnly = true)
public class ObjectCostItemService extends CrudService<ObjectCostItemMapper, ObjectCostItem> {

	@Autowired
	private ObjectCostItemMapper objectCostItemMapper;

	/**
	 * 添加款项
	 */
	@Transactional(readOnly = false)
	public boolean setCost(String objectId, ArchCostItem archCostItem) {
        int newNum = 0;
        ObjectCostItem objectCostItem;
        objectCostItem = new ObjectCostItem();
        objectCostItem.setCostitemId(archCostItem.getCostitemId());
        objectCostItem.setPclassID(archCostItem.getObjectId());
        objectCostItem.setObjectId(objectId);

        objectCostItem.setInShouldCorpus("1");
        objectCostItem.setInShouldInterest("1");

        objectCostItem.setInFactCorpus("1");
        objectCostItem.setInFactInterest("1");

        objectCostItem.setOutShouldCorpus("1");
        objectCostItem.setOutShouldInterest("1");

        objectCostItem.setOutFactCorpus("1");
        objectCostItem.setOutFactInterest("1");

        objectCostItem.setSelected("1");
        objectCostItem.setStatus("1");
        objectCostItem.setDelFlag("0");
        objectCostItem.preInsert();
        objectCostItemMapper.insertCost(objectCostItem);
        newNum++;
		if(newNum > 0){
			return true;
		}else {
			return false;
		}
	}

    /**
     * 根据objectId获取档案对应的款项
     * @param objectId
     * @return
     */
	@Transactional(readOnly = false)
    public List<ObjectCostItem> getCostList(String objectId){
	    ObjectCostItem objectCostItem = new ObjectCostItem();
        objectCostItem.setObjectId(objectId);
	    return objectCostItemMapper.findList(objectCostItem);
    }

	@Transactional(readOnly = false)
	public void deleteDictValue(String id) {objectCostItemMapper.deleteCost(id);
	}

}